﻿using RpcClient.Interface;
using RpcExtend.DAL;
using RpcExtend.Model.DB;

using RpcHelper;

namespace RpcExtend.Collect.Collect
{
    [RpcClient.Attr.ClassLifetimeAttr(RpcClient.Attr.ClassLifetimeType.单例)]
    internal class SysLogCollect : ISysLogCollect
    {
        private readonly IDelayDataSave<SystemErrorLog> _LogSave;
        private readonly IUnityCollect _Unity;
        public SysLogCollect(IUnityCollect unity)
        {
            this._Unity = unity;
            this._LogSave = new DelayDataSave<SystemErrorLog>(_SaveLog, 2, 10);
        }


        private void _SaveLog(ref SystemErrorLog[] datas)
        {
            _Unity.Resolve<ISystemLogDAL>().Adds(datas);
        }

        public void AddLog(SystemErrorLog[] logs)
        {
            _LogSave.AddData(logs);
        }
    }
}
